package com.fjp.heartguard.ui.question.fragment

import android.os.Bundle
import android.text.SpannableString
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import com.fjp.heartguard.R
import com.fjp.heartguard.app.App
import com.fjp.heartguard.app.base.BaseFragment
import com.fjp.heartguard.app.data.bean.SpanIndex
import com.fjp.heartguard.databinding.FragmentCognitiveAssessment3Binding
import com.fjp.heartguard.ui.question.QuestionActivity
import com.fjp.heartguard.viewmodel.CognitiveAssessment3ViewModel


class CognitiveAssessment3Fragment : BaseFragment<CognitiveAssessment3ViewModel, FragmentCognitiveAssessment3Binding>() {
    val spanindex1 = ArrayList<SpanIndex>()
    val spanindex2 = ArrayList<SpanIndex>()
    val spanindex3 = ArrayList<SpanIndex>()
    override fun initView(savedInstanceState: Bundle?) {
        mDatabind.viewmodel = mViewModel
        mDatabind.click = ClickProxy()
        mDatabind.questionTitle.setValue("认知功能评估（A）", resources.getColor(R.color.report_type_01), R.drawable.report_type_01)
        val colorSpan = ForegroundColorSpan(resources.getColor(R.color.colorAccent))

        val question1ss = SpannableString("A组：袜子、红色、茶几")
        val question2ss = SpannableString("B组：床、上衣、蓝色")
        val question3ss = SpannableString("C组：绿色、桌子、鞋子")
        spanindex1.add(SpanIndex(3, 5))
        spanindex1.add(SpanIndex(6, 8))
        spanindex1.add(SpanIndex(9, 11))

        spanindex2.add(SpanIndex(3, 4))
        spanindex2.add(SpanIndex(5, 7))
        spanindex2.add(SpanIndex(8, 10))

        spanindex3.add(SpanIndex(3, 5))
        spanindex3.add(SpanIndex(6, 8))
        spanindex3.add(SpanIndex(9, 11))

        val curSpanIndex1 = QuestionActivity.curSpanIndex1
        val curSpanIndex2 =QuestionActivity.curSpanIndex2
        val curSpanIndex3 = QuestionActivity.curSpanIndex3

        question1ss.setSpan(colorSpan, spanindex1[curSpanIndex1].start, spanindex1[curSpanIndex1].end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        question2ss.setSpan(colorSpan, spanindex2[curSpanIndex2].start, spanindex2[curSpanIndex2].end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        question3ss.setSpan(colorSpan, spanindex3[curSpanIndex3].start, spanindex3[curSpanIndex3].end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        mDatabind.question1TitleTv.text = question1ss
        mDatabind.question2TitleTv.text = question2ss
        mDatabind.question3TitleTv.text = question3ss

        mDatabind.question1Rg.setOnCheckedChangeListener { radioGroup, i ->
            if (i == R.id.sureRb) {
                QuestionActivity.olderInfoQuestion7.select[0].is_selected = 1
                QuestionActivity.olderInfoQuestion7.select[1].is_selected = 0
                QuestionActivity.olderInfoQuestion7.select[2].is_selected = 0
            } else if (i == R.id.tipSureRb) {
                QuestionActivity.olderInfoQuestion7.select[0].is_selected = 0
                QuestionActivity.olderInfoQuestion7.select[1].is_selected = 1
                QuestionActivity.olderInfoQuestion7.select[2].is_selected = 0
            } else {
                QuestionActivity.olderInfoQuestion7.select[0].is_selected = 0
                QuestionActivity.olderInfoQuestion7.select[1].is_selected = 0
                QuestionActivity.olderInfoQuestion7.select[2].is_selected = 1
            }
        }
        mDatabind.question2Rg.setOnCheckedChangeListener { radioGroup, i ->
            if (i == R.id.sure2Rb) {
                QuestionActivity.olderInfoQuestion8.select[0].is_selected = 1
                QuestionActivity.olderInfoQuestion8.select[1].is_selected = 0
                QuestionActivity.olderInfoQuestion8.select[2].is_selected = 0
            } else if (i == R.id.tipSure2Rb) {
                QuestionActivity.olderInfoQuestion8.select[0].is_selected = 0
                QuestionActivity.olderInfoQuestion8.select[1].is_selected = 1
                QuestionActivity.olderInfoQuestion8.select[2].is_selected = 0
            } else {
                QuestionActivity.olderInfoQuestion8.select[0].is_selected = 0
                QuestionActivity.olderInfoQuestion8.select[1].is_selected = 0
                QuestionActivity.olderInfoQuestion8.select[2].is_selected = 1
            }
        }
        mDatabind.question3Rg.setOnCheckedChangeListener { radioGroup, i ->
            if (i == R.id.sure3Rb) {
                QuestionActivity.olderInfoQuestion9.select[0].is_selected = 1
                QuestionActivity.olderInfoQuestion9.select[1].is_selected = 0
                QuestionActivity.olderInfoQuestion9.select[2].is_selected = 0
            } else if (i == R.id.tipSure3Rb) {
                QuestionActivity.olderInfoQuestion9.select[0].is_selected = 0
                QuestionActivity.olderInfoQuestion9.select[1].is_selected = 1
                QuestionActivity.olderInfoQuestion9.select[2].is_selected = 0
            } else {
                QuestionActivity.olderInfoQuestion9.select[0].is_selected = 0
                QuestionActivity.olderInfoQuestion9.select[1].is_selected = 0
                QuestionActivity.olderInfoQuestion9.select[2].is_selected = 1
            }
        }
    }

    inner class ClickProxy {

    }
}